package Controllers;

import java.rmi.RemoteException;

import Common.Helper;
import Models.ChessPieceModel;
import Models.Point2D;
import Models.StandardChessPieceModel;

public class BishopController implements ChessPieceControllerInterface {

	@Override
	public boolean legalMove(Point2D moveVector, ChessPieceModel chessPiece) throws RemoteException {
		if (Math.abs(moveVector.getX()) == Math.abs(moveVector.getY())) {
			return true;
		}
		else {
		return false;
		}
	}


	@Override
	public boolean legalCapture(Point2D moveVector, ChessPieceModel chessPiece) throws RemoteException {
		
		return legalMove(moveVector, chessPiece);
	}

	@Override
	public boolean canPieceMoveNotify(Point2D from, Point2D to, ChessPieceModel chessPiece)
			throws RemoteException {
		
		return legalMove(Helper.calculateVector(from, to), chessPiece);
		
	}
	

	public static ChessPieceModel getNew() throws RemoteException {
		ChessPieceModel bishop = new StandardChessPieceModel();
		ChessPieceControllerInterface bishopController = new BishopController();
		bishop.addCanPieceMoveListener(bishopController);
		return bishop;
	}


}
